package o;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

class rn implements Closeable {
    private final InputStream ˊ;
    private final Charset ˋ;
    private int ˎ;
    private byte[] ˏ;
    private int ॱ;

    public rn(InputStream inputStream, Charset charset) {
        this(inputStream, 8192, charset);
    }

    public rn(InputStream inputStream, int i, Charset charset) {
        if (inputStream == null || charset == null) {
            throw new NullPointerException();
        } else if (i < 0) {
            throw new IllegalArgumentException("capacity <= 0");
        } else if (charset.equals(rs.ॱ)) {
            this.ˊ = inputStream;
            this.ˋ = charset;
            this.ˏ = new byte[i];
        } else {
            throw new IllegalArgumentException("Unsupported encoding");
        }
    }

    public void close() throws IOException {
        synchronized (this.ˊ) {
            if (this.ˏ != null) {
                this.ˏ = null;
                this.ˊ.close();
            }
        }
    }

    public String ॱ() throws IOException {
        String str;
        synchronized (this.ˊ) {
            if (this.ˏ == null) {
                throw new IOException("LineReader is closed");
            }
            int i;
            if (this.ॱ >= this.ˎ) {
                ˎ();
            }
            int i2 = this.ॱ;
            while (i2 != this.ˎ) {
                if (this.ˏ[i2] == (byte) 10) {
                    int i3 = (i2 == this.ॱ || this.ˏ[i2 - 1] != (byte) 13) ? i2 : i2 - 1;
                    str = new String(this.ˏ, this.ॱ, i3 - this.ॱ, this.ˋ.name());
                    this.ॱ = i2 + 1;
                } else {
                    i2++;
                }
            }
            ByteArrayOutputStream anonymousClass3 = new ByteArrayOutputStream(this, (this.ˎ - this.ॱ) + 80) {
                final /* synthetic */ rn ˊ;

                public String toString() {
                    int i = (this.count <= 0 || this.buf[this.count - 1] != (byte) 13) ? this.count : this.count - 1;
                    try {
                        return new String(this.buf, 0, i, this.ˊ.ˋ.name());
                    } catch (UnsupportedEncodingException e) {
                        throw new AssertionError(e);
                    }
                }
            };
            loop1:
            while (true) {
                anonymousClass3.write(this.ˏ, this.ॱ, this.ˎ - this.ॱ);
                this.ˎ = -1;
                ˎ();
                i = this.ॱ;
                while (i != this.ˎ) {
                    if (this.ˏ[i] == (byte) 10) {
                        break loop1;
                    }
                    i++;
                }
            }
            if (i != this.ॱ) {
                anonymousClass3.write(this.ˏ, this.ॱ, i - this.ॱ);
            }
            this.ॱ = i + 1;
            str = anonymousClass3.toString();
        }
        return str;
    }

    public boolean ˊ() {
        return this.ˎ == -1;
    }

    private void ˎ() throws IOException {
        int read = this.ˊ.read(this.ˏ, 0, this.ˏ.length);
        if (read == -1) {
            throw new EOFException();
        }
        this.ॱ = 0;
        this.ˎ = read;
    }
}
